package model

import "gorm.io/gorm"

type Message struct {
	gorm.Model
	UserId   int    `gorm:"type:int" json:"userId"`
	FriendId int    `gorm:"type:int" json:"friendId"`
	Content  string `gorm:"type:varchar(30)" json:"content"`
	Status   string `gorm:"type:varchar(10)" json:"status"`
}

// 信息发送
func (m *Message) AddMessage(db *gorm.DB) error {
	return db.Debug().Create(&m).Error
}

// 聊天记录
func (m *Message) ListMessage(db *gorm.DB, userId int) (list []*Message, err error) {
	err = db.Debug().Where("user_id=?", userId).Find(&list).Order("created_at desc").Error
	return list, err

}
